// 权限配置
export const roles = {
  guanliyuan: {
    name: '管理员',
    permissions: ['*'] // 所有权限
  },
  dianzhang: {
    name: '店长',
    permissions: [
      'view_dashboard',
      'manage_products',
      'manage_orders',
      'manage_staff',
      'manage_inventory',
      'view_reports',
      'view_logs'
    ]
  },
  shouyinyuan: {
    name: '收银员',
    permissions: [
      'view_dashboard',
      'create_order',
      'manage_orders',
      'view_products',
      'view_inventory'
    ]
  },
  kafeishi: {
    name: '咖啡师',
    permissions: [
      'view_dashboard',
      'view_orders',
      'update_order_status',
      'view_products',
      'view_inventory'
    ]
  }
}

// 路由权限配置
export const routePermissions = {
  '/dashboard': ['view_dashboard'],
  '/products': ['manage_products', 'view_products'],
  '/orders': ['manage_orders', 'create_order', 'view_orders'],
  '/staff': ['manage_staff'],
  '/inventory': ['manage_inventory', 'view_inventory'],
  '/operation-log': ['view_logs'],
  '/reports': ['view_reports']
}

// 检查用户是否有权限
export function hasPermission(userRole, permission) {
  if (!userRole || !roles[userRole]) return false
  return roles[userRole].permissions.includes('*') || 
         roles[userRole].permissions.includes(permission)
}

// 检查用户是否有路由权限
export function hasRoutePermission(userRole, route) {
  const requiredPermissions = routePermissions[route]
  if (!requiredPermissions) return true
  return requiredPermissions.some(permission => hasPermission(userRole, permission))
} 